import { createRouter, createWebHistory } from 'vue-router'

import count from '../views/Count.vue'
import cart from '../views/Cart.vue'
import todoList from '../views/TodoList.vue'
import newslist from '../views/Newslist.vue'
import detail from '../views/NewsDetail.vue'
import movielist from '../views/MovieList.vue'

import myData from '../views/senddata/MyData.vue'
import Yeye from '../views/grandpa/Yeye.vue'

//自定义路由规则   跳转的url映射   return 'user/list' => userlist.jsp
const r = [
  {
    path: '/url_count',
    name: 'name_count',
    component: count
  },
  {
    name: 'name_cart',
    path: '/cart',
    alias: '/',
    component: cart
  },
  {
    path: '/todoList',
    name: 'todoList',
    component: todoList
  },
  {
    path: '/movielist',
    name: 'movielist',
    component: movielist
  },
  {
    path: '/myData',
    name: 'myData',
    component: myData
  },
  {
    path: '/yeye',
    name: 'yeye',
    component: Yeye
  },
  {
    path: '/newslist',
    name: 'newslist',
    component: newslist,
    children: [
      {
        name: 'wang', //如果是用的params传参 1: 一定要有name属性 2:path一定要用:prop占位
        path: 'detail', //params 的写法: 'detail/:id/:title/:content',
        component: detail,
        //props: true
        props(r) {
          return r.query
        }
      }
    ]
  }
]
//定义路由规则对象
const route = createRouter({
  history: createWebHistory(),
  routes: r
})

export default route
